﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CKNetFrameWork
{
    public partial class Frm_Login : Form
    {
        private LSY.BLL.LSY_AgentTab m_bllAccounts_Users = new LSY.BLL.LSY_AgentTab();
       
        public Frm_Login()
        {
            InitializeComponent();

        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
            if (this.comboBoxOrderPerson.Text == "")
            {
                this.errorProvider1.SetError(this.comboBoxOrderPerson, "用户名称不能为空！");
                return;
            }
            else
            {
                this.errorProvider1.SetError(this.comboBoxOrderPerson, "");
            }

            if (this.textBox_password.Text == "")
            {
                this.errorProvider1.SetError(this.textBox_password, "密码不能为空！");
                return;
            }
            else
            {
                this.errorProvider1.SetError(this.textBox_password, "");
            }

         
            string strPass = this.textBox_password.Text;
       

            DataSet dsLogin = m_bllAccounts_Users.GetUserInfoByLoginInfo(this.comboBoxOrderPerson.Text, strPass);

            //DataSet dsLogin = m_bllAccounts_Users.GetUserInfoByLoginInfo(this.textBox_username.Text, this.textBox_password.Text);
            if (dsLogin.Tables[0].Rows.Count > 0)
            {
                Frm_Main.m_nLoginUserId = (int)dsLogin.Tables[0].Rows[0]["LSY_AgentTabid"];
                this.DialogResult = DialogResult.OK;
                //得到该登录用户的权限
            }
            else
            {
        
                MessageBox.Show("用户名或密码错误,请重新输入！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBox_password.Text = "";

                return;
            }
        }

        private void buttonExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Frm_Login_Load(object sender, EventArgs e)
        {
            DataSet ds = m_bllAccounts_Users.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxOrderPerson.DataSource = ds.Tables[0];
                this.comboBoxOrderPerson.DisplayMember = "代理商登录用户名";
                this.comboBoxOrderPerson.ValueMember = "LSY_AgentTabID";
                this.comboBoxOrderPerson.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxOrderPerson.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxOrderPerson.SelectedIndex = 0;
            }

        }

        private void textBox_username_TextChanged(object sender, EventArgs e)
        {
            //this.textBox_username.Focus();
        }

        private void Frm_Login_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void textBox_username_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                buttonLogin_Click(this, null);
        }

        private void comboBoxOrderPerson_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                buttonLogin_Click(this, null);
        }

        private void textBox_password_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                buttonLogin_Click(this, null);
        }
    }
}
